import bs4
import json
import os
import urllib.request
import urllib.parse


def get_events(city, request_size):
	
	result_list = []
	start_idx = 1
	
	while len(result_list) < request_size:
		url = "http://api.douban.com/event/location/%s?start-index=%d&max-results=50&alt=json" %(city, start_idx)
		res = urllib.request.urlopen(url)
		result = json.loads((res.read()).decode('utf-8'))
		result_list.extend(result['entry'])

		if len(result_list) == int(result['openSearch:totalResults']['$t']):
			break

		start_idx += len(result['entry'])
	
	return result_list[0: request_size]
